import * as echarts from 'echarts'
import { onUnmounted } from 'vue'

export default function useEchart(divEl) {
  let mychartInstance = echarts.init(divEl, null, { renderer: 'svg' })

  const setOption = (option) => {
    mychartInstance.setOption(option)
  }

  function resizeEchart() {
    mychartInstance.resize()
  }

  onUnmounted(() => {
    mychartInstance.dispose()
  })

  return {
    mychartInstance,
    setOption,
    resizeEchart,
  }
}
